﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ESP.Tool;
using System.Data;

namespace ShortUrl.Web.Controllers
{
    public class ShortUrlController : Controller
    {
        // GET: ShortUrl
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult ajax()
        {
            
            string action = ESPRequest.GetString("action");

            switch(action)
            {
                case "create":
                    string SourceUrl = ESPRequest.GetString("surl"); 

                    Models.ShortUrlModel sm = Models.ShortUrlModel.Create(ESP.Tool.SystemDefinition.SystemSetting.GetAppSettingValue("ShortBaseUrl"), SourceUrl);
                    
                    return Json(sm, JsonRequestBehavior.AllowGet);
                    break;
                case "list":
                    DataTable dt = Models.ShortUrlModel.GetList();

                    return Json(dt.ToJSON(), JsonRequestBehavior.AllowGet);
                    break;
                default:
                    break;
            }

            return Json("", JsonRequestBehavior.AllowGet);
        }
    }
}